/**
 * Created by lijingwen on 2015-02-13.
 * 公共方法
 */

$(function(){
    loadlogo("resource/img/favicon.ico");
});

function loadlogo(url){
    var link = document.createElement("link");
    link.type = "image/x-icon";
    link.rel  = "shortcut icon";
    link.href  = url;
    var head = document.getElementsByTagName("head")[0];
    head.appendChild(link);
    console.log('finished logo');
}

var quickSort = function (arr) {
    if (arr.length <= 1) {
        return arr;
    }

    var pivotIndex = Math.floor(arr.length / 2);

    var pivot = arr.splice(pivotIndex, 1)[0];
    var left = [];
    var right = [];
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] < pivot) {
            left.push(arr[i]);
        } else {
            right.push(arr[i]);
        }
    }
    return quickSort(left).concat([pivot], quickSort(right));
};

var DoublequickSort = function (arr1,arr2) {
    if (arr1.length <= 1) {
        return {
            'arr1':arr1,
            'arr2':arr2
        };
    }

    var pivotIndex = Math.floor(arr1.length / 2);

    var pivot = arr1.splice(pivotIndex, 1)[0];
    var left = [];
    var right = [];
    for (var i = 0; i < arr1.length; i++) {
        if (arr1[i] < pivot) {
            left.push(arr1[i]);
        } else {
            right.push(arr1[i]);
        }
    }
    return quickSort(left).concat([pivot], quickSort(right));
};



function DoubleBubbleSort(arr1,arr2){
    for(var i=0;i<arr1.length;i++){
        for(var j=i;j<arr1.length;j++){
            if(arr1[i]<arr1[j]){
                var temp=arr1[i];
                arr1[i]=arr1[j];
                arr1[j]=temp;

                //second
                var temp2=arr2[i];
                arr2[i]=arr2[j];
                arr2[j]=temp2;

            }
        }
    }
    return {
        'arr1':arr1,
        'arr2':arr2
    };

}